/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-08-19
 * 17:53
 */
public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
public class Test {
    public static void main(String[] args) {

    }
    class Solution {
        public boolean isSymmetric(TreeNode root) {
            if(root==null){//空树为真
                return true;
            }
            return isSymmetricChild(root.left,root.right);//判断左右子树是否相等
        }
        public boolean isSymmetricChild(TreeNode rootLeft,TreeNode rootRight){
            if(rootLeft==null&&rootRight!=null||rootLeft!=null&&rootRight==null){//左右子树结构不同为假
                return false;
            }
            if(rootLeft==null&&rootRight==null){//左右子树都为空，返回true
                return true;
            }
            if(rootLeft.val!=rootRight.val){//判断左右子树值是否相等
                return false;
            }
            return  isSymmetricChild(rootLeft.left,rootRight.right)&&
                    isSymmetricChild(rootLeft.right,rootRight.left);//判断子树的左右子树是否对称
        }
    }
}
